<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <!-- <el-form-item label="商户账户名称：">
          <el-select v-model="formInline.region" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="商户账户名称：">
          <el-input v-model="formInline.merchantName" placeholder="请输入商户账户名称"></el-input>
        </el-form-item>
        <el-form-item label="店铺名称：">
          <el-input v-model="formInline.shopName" placeholder="请输入店铺名称"></el-input>
        </el-form-item>
        <el-form-item label="支付时间：">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交易明细类型：">
          <el-select v-model="billType" multiple placeholder="请选择" filterable>
            <el-option v-for="item in options2" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="管辖区域：">
          <el-select v-model="formInline.areaId" placeholder="请选择" filterable>
            <el-option v-for="item in areaSelect" :key="item.id" :label="item.value" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户查询：">
          <el-input v-model="formInline.customerQuery" placeholder="卡号/手机号"></el-input>
        </el-form-item>
        <el-form-item label="卡类型：">
          <el-select v-model="formInline.cardType" placeholder="请选择" filterable>
            <el-option v-for="item in cardTypeLs" :key="item.id" :label="item.value" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来源：">
          <el-select v-model="formInline.paySource" placeholder="请选择" filterable>
            <el-option v-for="item in paySourceLs" :key="item.id" :label="item.value" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付公司：">
          <el-select v-model="formInline.payProvider" placeholder="请选择" filterable>
            <el-option v-for="item in payProviderLs" :key="item.id" :label="item.value" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <export-excel-button title="账单列表" action="/merchant/bill/v1/merchantBgBills/export" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:payProvider="{ scope }">
          <dict-tag :options="payProviderLs" :value="scope.row.payProvider" />
        </template>
        <template v-slot:operate="{ scope }">
          <el-button @click="lookDetail(scope.row)" v-if="scope.row.billType!=2&&scope.row.billType!=5&&scope.row.billType!=8&&scope.row.billType!=13&&scope.row.billType!=15">查看</el-button>
          <el-button @click="lookInsureDetail(scope.row)" type="primary" v-if="scope.row.billType==15">查看</el-button>
        </template>
      </ex-table>
    </div>
    <!-- 保险提现详情 -->
    <insureDetail v-if="detailDialog" :visible.sync="detailDialog" :id="detailDialogId" />
  </div>
</template>
<script>
  // components
  import {
    adminGetMerchantBill,
    adminGetMerchantBillNew,
    adminDict,
  } from "@/api/moneyManagement";
  import {
    userAreaSelect
  } from "@/api/common";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import insureDetail from "./components/insureDetail";
  export default {
    name: "billList",
    components: {
      ExportExcelButton,insureDetail
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        formInline: {
          areaId: '', //区域id
          merchantName: "", //商家名称
          shopName: "", //店铺名称
          transactionTimeStart: "", //支付开始时间
          transactionTimeEnd: "", //支付结束
          billType: [], //账单类型（1 用户消费订单 2 提现订单）
          customerQuery: '', //卡号/手机号
          cardType: '', //预付卡类型 asset_card_type
          paySource:'', // 支付来源 merchant_order_pay_source
          payProvider:'',//支付公司
        },
        detailDialog: false,
        detailDialogId:'',
        date: [],
        areaSelect: [], //区域下拉
        cardTypeLs: [], //卡类型
        paySourceLs: [], //来源类型
        payProviderLs:[],//支付公司下拉
        options: [{
            value: "0",
            label: "请选择",
          },
          {
            value: "1",
            label: "商家名称1",
          },
          {
            value: "2",
            label: "商家名称2",
          },
        ],
        billType: [],
        options2: [],
        options3: [],
        tableData: [],
        tableColumn: [{
            prop: "areaName",
            label: "管辖区域",
            width: 100
          },
          {
            prop: "merchantName",
            label: "商户账号名称",
            width: 120
          },
          {
            prop: "shopName",
            label: "店铺名称"
          },
          {
            prop: "relevancyNo",
            label: "交易单号"
          },
          {
            prop: "relevancySerialNo",
            label: "交易流水"
          },
          {
            prop: "cardNo",
            label: "卡号"
          },
          {
            prop: "cardTypeDict",
            label: "卡类型"
          },
          {
            prop: "customerPhone",
            label: "手机号",
            width: 120
          },
          {
            prop: "transactionTime",
            label: "交易成功时间",
            width: 160
          },
          {
            prop: "billTypeDict",
            label: "交易明细类型",
            width: 120
          },
          {
            prop: "billMoney",
            label: "交易金额",
            width: 120
          },
          {
            prop: "discount",
            label: "优惠",
            width: 120
          },
          {
            prop: "cardPayMoney",
            label: "卡余额支付",
            width: 120
          },
          {
            prop: "receivedMoney",
            label: "现金支付",
            width: 120
          },
          {
            prop: "platformProcedureFee",
            label: "手续费",
            width: 120
          },
          {
            label: "可用金额",
            width: 120,
            children: [{
                prop: "withdrawMoney",
                label: "收入/支出",
                width: 120
              },
              {
                prop: "changeWithdrawMoney",
                label: "可用余额",
                width: 120
              },
            ],
          },
          {
            label: "存管金额",
            width: 120,
            children: [{
                prop: "freezeMoney",
                label: "收入/支出",
                width: 120
              },
              {
                prop: "changeFreezeMoney",
                label: "存管余额",
                width: 120
              },
              {
                prop: "cardFreezeMoney",
                label: "卡存管",
                width: 120
              },
              {
                prop: "insFreezeMoney",
                label: "保险存管",
                width: 120
              },
            ],
          },
          {
            // prop: "payProvider",
            slot: true,
            slotName: "payProvider",
            label: "支付公司",
            width: "180"
          },
          {
            prop: "paySourceDict",
            label: "来源",
            width: 120
          },
          {
            prop: "remark",
            label: "备注",
            width: 120
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate",
            width: 180
          },
        ],
      };
    },
    computed: {
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        return params;
      },
    },
    mounted() {
      
      this.getlinkagelist();
      this.getTransactiontype();
      this.getAssetCardType();
      this.formInline.customerQuery = this.$route.query.phone 
      this.billType[0] = this.$route.query.type 
      this.getList();
      this.getUserAreaSelect();
      this.getpaySourceList()
      
    },
    methods: {
      getUserAreaSelect() {
        //查询用户区域下拉框
        userAreaSelect().then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.areaSelect = arr.concat(res.result);
        });
      },
      getlinkagelist() {
        //获取字典值
        const params = {
          dictType: "fund_flow_type,pay_provider",
        };
        adminDict(params).then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.options3 = arr.concat(res.result[0].dictList);
          this.payProviderLs = arr.concat(res.result[1].dictList);
        });
      },
      getpaySourceList() {
        //支付来源
        const params = {
          dictType: "merchant_order_pay_source",
        };
        adminDict(params).then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.paySourceLs = arr.concat(res.result[0].dictList);
        });
      },
      getTransactiontype() {
        //获取交易明细类型
        const params = {
          dictType: "merchant_bill_type",
        };
        adminDict(params).then((res) => {
          this.options2 = res.result[0].dictList;
        });
      },
      getAssetCardType() {
        //获取卡类型
        const params = {
          dictType: "asset_card_type",
        };
        adminDict(params).then((res) => {
          this.cardTypeLs = res.result[0].dictList;
        });
      },
      lookDetail(e) {
        console.log(e);
        this.$router.push({
          path: "/moneyManagement/bill-detail",
          query: {
            orderId: e.relevancyNo,
            type: e.billType,
            relevancyNo: e.relevancyNo,
          },
        });
      },
      search() {
        //搜索
        console.log(this.formInline);
        this.formInline.transactionTimeStart = this.date[0];
        this.formInline.transactionTimeEnd = this.date[1];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        this.billType = "";
        // this.formInline.billType = [];
        // this.formInline.fundFlow = ''
        // this.formInline.billType = ''
        this.date = [];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        //联动信息
        console.log(this.billType);
        if (this.billType != undefined && this.billType.length > 0) {
          console.log(111);
          this.formInline.billType = this.billType.join();
        } else {
          this.formInline.billType = ''
        }
        console.log("billType", this.formInline.billType);
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        adminGetMerchantBillNew(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;
            this.tableData = records;
            this.$refs.table.pageOptions.total = total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //查看保险提现详情
      lookInsureDetail(row){
        this.detailDialogId = row.relevancyNo
        this.detailDialog = true
      },
    },
  };

</script>
<style lang="scss">
  .el-card-title {
    font-size: 20px;
  }

</style>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 40px;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }

</style>
